<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/16 0016
  Time: 上午 10:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <link href="css/style.css" rel="stylesheet"/>
    <link href="css/base.css" rel="stylesheet"/>
    <script src="js/jquery1.42.min.js" type="text/javascript"></script>
    <script src="js/jquery.SuperSlide.2.1.3.js" type="text/javascript"></script>
    <script src="js/flexible.min.js" type="text/javascript"></script>
    <title>密码</title>
</head>
<body style="background-color: rgb(242,242,242);">
<div>
    <input type="hidden" id ="id" value="${userId}">
    <div class='pwd'><span>原密码：</span><input id="oldPassword"  placeholder="6-16为英文字母，数字"></div>
    <div class='pwd'><span>新密码：</span><input id="newPassword"  placeholder="6-16为英文字母，数字"></div>
    <div class='pwd'><span>确认密码：</span><input id="truePassword"  placeholder="6-16为英文字母，数字"></div>
    <div class="grzxInfo_btn" onclick="upPassword()">确定修改</div>

</div>
</body>
</html>

<script>
            function upPassword() {
                var id =$("#id").val();
                console.log(id);
                var oldpwd = $("#oldPassword").val();
                var newpwd = $("#newPassword").val();
                var truePassword = $("#truePassword").val();
                var count= /^[0-9a-zA-Z]{6,16}$/;
                if(count.test(newpwd)==false){
                    alert("密码格式不正确");
                    return  false;
                }
                console.log(newpwd);
                if (truePassword != newpwd) {
                    //console.log(truePassword);
                    alert("两次输入密码不一致");
                    return false;
                }
                console.log(oldpwd);
                $.ajax({
                    url: '/mobile/updatePwd',
                    type: 'POST',
                    async: true,
                    data: {
                        id:id,
                        oldpwd: oldpwd,
                        newpwd: newpwd
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == "true") {
                            window.location.href="/mobile/toMyInfo";
                        } else {
                            alert("原密码错误");
                        }
                    },
                });
            };
</script>
